package com.yygo.dao.hibernate;

import com.yygo.Constants;
import com.yygo.dao.DealerDao;
import com.yygo.model.BondCompany;
import com.yygo.model.Dealer;
import com.yygo.model.User;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by tiansha on 2015/6/17.
 */
@Repository("dealerDao")
public class DealerDaoHibernate extends GenericDaoHibernate<Dealer, Long> implements DealerDao {

    public DealerDaoHibernate() {
        super(Dealer.class);
    }

    public List<User> getUsers(Long dealerId) {
        Dealer dealer = super.get(dealerId);
        List<User> users = new ArrayList<>();
        for (User user : dealer.getUsers()) {
            user.getUsername();
            if (!user.hasRole(Constants.DEALER_ADMIN_ROLE))
                users.add(user);
        }

        return users;
    }

}
